<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>

    </style>
</head>

<body>

    <div id="box">


    </div>


    <script src="./js/react.js"></script>
    <script src="./js/react-dom.js"></script>
    <script src="./js/prop-types.js"></script>
    <script src="./js/babel.min.js"></script>

    <script type="text/babel">

        // 定义一个类组件
        class Book extends React.Component {

            constructor(){
                super();
                this.userpass = null;
                // 3、第三种： 创建ref对象，把ref对象赋给某个标签的ref属性
                // 3.1）、创建ref对象 （用React.createRef()）
                this.usersex = React.createRef();
            }

            testf = () => {
                console.log("this.refs.username.value", this.refs.username.value);
            }

            testf02=()=>{
                console.log("this.userpass.value",this.userpass.value);
            }

            testf03=()=>{
                console.log("this.usersex.current.value",this.usersex.current.value);
            }

            render() {
                return (
                    <div>
                        <h1>书籍组件</h1>
                        {/*1、给ref属性赋值为 字符串 */}
                        <input type="text" ref="username" /><br />
                        <input type="button" value="测试" onClick={this.testf} />
                        <hr />
                        {/*2、给ref属性赋值为 回调函数，回调函数的参数就是dom对象 */}
                        <input type="text" ref={el=>{this.userpass=el}} /><br />
                        <input type="button" value="测试" onClick={this.testf02} />
                        <hr />
                        {/*3、
                            // 3.2）、给ref属性赋值为ref对象
                        */}                        
                        <input type="text" ref={this.usersex} /><br />
                        <input type="button" value="测试" onClick={this.testf03} />
                     
                    </div>
                )
            }

        }



        const root = (<div>
            <h1>组件：</h1>
            <Book>
                <p>我是书中的p</p>
            </Book>
        </div>
        );

        ReactDOM.render(root, document.getElementById("box"));


    </script>
</body>

</html>